package com.zp.collection;

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedList;

public class CollectionsTest {
	public static void main(String[] args){
		
		LinkedList<Integer> list = new LinkedList<Integer>();
		
		list.add(2);
		list.add(4);
		list.add(1);
		list.add(7);
		
		//Collections的reverseOrder()方法：倒序排序比较器，返回Comparator类型，与之相应sort()方法如下；
		Comparator<Integer> c = Collections.reverseOrder();
		
		//Collections的sort()方法：根据不同比较器进行排序，无返回值；
		Collections.sort(list,c);
		
		for(Iterator<Integer> iter = list.iterator();iter.hasNext();){
			Integer i = iter.next();
			System.out.println(i);
		}
		
		System.out.println("=================");
		
		//将集合随机排序；
		Collections.shuffle(list);
		System.out.println(list);
		
		//获取集合中最大值和最小值；
		Integer max = Collections.max(list);
		Integer min = Collections.min(list);
		
		System.out.println("max="+max+";"+"min"+min);
		
	}
}
